
local locplayer = ac.player.self
local show_update = {}
local show_hide = {}

ac.game:event '游戏-注册显示UI'(function(_,ui,esc_hide)
    show_update[ui] = true
    if esc_hide then
        show_hide[ui] = true
    end
end)


ac.hardware:event '界面绘制'(function(_,frame)
    for ui in pairs(show_update) do
        if ui:is_absolute_show() then
            ui:notify('update',frame)
        end
    end
end)


ac.hardware:event '键盘按下'(function(_,key)
    if japi.GetChatState() then
        return
    end
    
    if key=='ESC' then
        for ui in pairs(show_hide) do
            ui:hide()
        end
    end

    -- if name then
    --     ac.sync(name)
    -- end
    --if code==192 and player.pet then
    --    player:set_camera(player.pet)
    --    player:select_unit(player.pet)
    --end
end)


--处理宽屏
local message = ac.message
if message.client_online then
    local win_w = japi.DzGetWindowWidth()
    local win_h = japi.DzGetWindowHeight()
    if japi.IsWindowMode() then
        local w = math.floor(win_w/16)*16
        local h = math.floor(win_h/9) * 9
        if h/9>w/16 then
            w = h*1920 / 1080
        end
        local x = math.floor((win_w - w) / 2)
        local y = math.floor((win_h - h) / 2)
        japi.SetWindowSize(w,h)
        japi.SetWindowPos(x,y)
        --宽屏
        japi.DzEnableWideScreen(true)
    else
        --japi.SetWindowSize(win_w/0.6,win_h/0.6)
    end
end